package com.desire.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class DirectConfig {

    /**
     * 向ioc容器注入直接交换器
     *
     * @return
     */
    @Bean
    DirectExchange directExchange() {
        return new DirectExchange("mqsb-direct");
    }

    @Bean
    Queue commonlogQueue() {
        return new Queue("commonlog");
    }

    @Bean
    Queue errorlogQueue() {
        return new Queue("errorlog");
    }

    @Bean
    Binding directBinding(DirectExchange exchange, @Qualifier("commonlogQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("info");
    }

    @Bean
    Binding directBinding2(DirectExchange exchange, @Qualifier("commonlogQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("debug");
    }

    @Bean
    Binding directBinding3(DirectExchange exchange, @Qualifier("commonlogQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("warn");
    }

    @Bean
    Binding directBinding4(DirectExchange exchange, @Qualifier("errorlogQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("error");
    }
}
